var http = require('http');
var fs = require('fs');

function serveStaticFile(res, path) {
	fs.readFile(__dirname + path, function(err, data) {
		if (err) {
			res.writeHead(404, {'Content-type': 'text/plain'});
			res.end('Not Found');
		} else{
			res.writeHead(200, {'Content-type': 'text/plain'});
			res.end(data);
		};
	});
}

http.createServer(function(req, res) {
    var path = req.url.replace(/\/?(?:\?.*)?$/, '');

    switch(path) {
    	case '':
    	res.writeHead(200, {'Content-type': 'text/plain'});
    	res.end('Homepage');
    	break;

    	case '/about':
    	res.writeHead(200, {'Content-type': 'text/plain'});
    	res.end('About');
    	break;

    	default:
    	serveStaticFile(res, path);
    }
}).listen(3000);
